#ifndef __FLETCHER16_H__
#define __FLETCHER16_H__

#include "kernel.h"
#include "kernel_id.h"
#include "ecrobot_interface.h"

void fletcher16( U8 *checkA, U8 *checkB, const U8 *data, int len )
{
	U8 sum1 = 0xff, sum2 = 0xff;
    while (len) {
            int tlen = len > 21 ? 21 : len;
            len -= tlen;
            do {
                    sum1 += *data++;
                    sum2 += sum1;
            } while (--tlen);
            sum1 = (sum1 & 0xff) + (sum1 >> 8);
            sum2 = (sum2 & 0xff) + (sum2 >> 8);
    }
    sum1 = (sum1 & 0xff) + (sum1 >> 8);
    sum2 = (sum2 & 0xff) + (sum2 >> 8);
	*checkA = sum1;
	*checkB = sum2;
}

#endif
